<?php
/*********************************************
  CPG Dragonfly™ CMS
  ********************************************
  Copyright © 2004 - 2007 by CPG-Nuke Dev Team
  http://dragonflycms.org

  Dragonfly is released under the terms and conditions
  of the GNU GPL version 2 or any later version
**********************************************/
if (!defined('CPG_NUKE')) { exit; }

global $prefix, $db;

if ((SEARCHBOT && Client::$verified) || (!SEARCHBOT && Client::$name)) {
	$var = $db->escape_string(Client::$name);
} else {
	$var = 'Other';
}
$os = Client::$os ? $db->escape_string(Client::$os) : 'Other';
$type = SEARCHBOT ? 'bot' : 'browser';
$now = explode('-', date('d-m-Y-H'));
if (!$db->exec("UPDATE {$prefix}_counter SET count=count+1 WHERE var='$var' AND type='$type'")) {
	$db->query("INSERT INTO {$prefix}_counter (type, var, count) VALUES ('$type', '$var', 1)");
}
if (!SEARCHBOT) {
	if (!$db->exec("UPDATE {$prefix}_counter SET count=count+1 WHERE var='$os' AND type='os'")) {
		$db->query("INSERT INTO {$prefix}_counter (type, var, count) VALUES ('os', '$os', 1)");
	}
}
if (!$db->exec('UPDATE '.$prefix."_stats_hour SET hits=hits+1 WHERE (year=$now[2]) AND (month=$now[1]) AND (date=$now[0]) AND (hour=$now[3])")) {
	$db->query('INSERT INTO '.$prefix."_stats_hour (year, month, date, hour, hits) VALUES ($now[2], $now[1], $now[0], $now[3], 1)");
}
